package com.csdj.t309.geamtest.controller;


import com.csdj.t309.geamtest.common.CacheConstant;
import com.csdj.t309.geamtest.common.WebResult;
import com.csdj.t309.geamtest.common.WebResultMsgCode;
import com.csdj.t309.geamtest.entity.Jigsaw;
import com.csdj.t309.geamtest.service.JigsawService;
import com.csdj.t309.geamtest.service.RedisService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 田港
 * @since 2022-01-12
 */
@RestController
@RequestMapping("/jigsaw")
public class JigsawController {
    @Resource
    private JigsawService jigsawService;
    @Resource
    private RedisService redisService;

    @GetMapping("/seljs")
    public WebResult seljs(){
        List<Jigsaw> js = jigsawService.selJS();
        return new WebResult(WebResultMsgCode.SUCCESS).putData("js",js);
    }

    @GetMapping("/selmanghe")
    public WebResult selMangHe(@RequestParam(value = "id",required = true) Integer id){
        Jigsaw jigsaw = jigsawService.selMangHe(id);
        return new WebResult(WebResultMsgCode.SUCCESS).putData("jigsaw",jigsaw);
    }

    @GetMapping("/chouJiang")
    public WebResult chouJiang(@RequestParam(value = "cishu",required = true)Integer cishu,
                               @RequestParam(value = "jsId",required = true)Integer jsId,
                               HttpServletRequest request){
        List suiJi = jigsawService.suiJiShu(cishu,jsId,redisService.getObject(CacheConstant.HEADER_UID+request.getHeader(CacheConstant.HEADER_UID)));
        if(suiJi!=null){
            return new WebResult(WebResultMsgCode.SUCCESS).putData("suiJi",suiJi);
        }
        return new WebResult(WebResultMsgCode.SUCCESS).putData("suiJi",0);
    }
}
